package com.example.orders.service.impl;

import com.example.orders.pojo.TbOrder;
import com.example.orders.mapper.TbOrderMapper;
import com.example.orders.pojo.TbUser;
import com.example.orders.service.ITbOrderService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 梁峰
 * @since 2021-12-10
 */
@Service
public class TbOrderServiceImpl extends ServiceImpl<TbOrderMapper, TbOrder> implements ITbOrderService {
    @Autowired
    TbOrderMapper tbOrderMapper;
    @Autowired
    RestTemplate restTemplate;
    @Override
    public TbOrder getOrder(Long id) {
        TbOrder tbOrder = tbOrderMapper.selectById(id);
        Long userId = tbOrder.getUserId();

        //远程访问
        //String url ="http://localhost:8081/users/"+userId;
        String url = "http://userservice/users/"+userId;

        TbUser tbUser = restTemplate.getForObject(url, TbUser.class);
        tbOrder.setUser(tbUser);
        return tbOrder;

    }
}
